//
//  LocationViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/27.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "LocationViewController.h"
#import "NearbyTableViewCell.h"//附近cell
#import "SearchAddressViewController.h"//搜索Controller

@interface LocationViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
/**搜索*/
@property (weak, nonatomic) IBOutlet UITextField *searchAddress;
@property (weak, nonatomic) IBOutlet UILabel *searchLabel;
@property (weak, nonatomic) IBOutlet UIView *searchbgView;
/**地图*/
@property (weak, nonatomic) IBOutlet UIView *mapView;
/**附近*/
@property (weak, nonatomic) IBOutlet UIView *nearbyView;
@property (weak, nonatomic) IBOutlet UITableView *nearbyTableView;


@end

@implementation LocationViewController

 static NSString *const NearbyTableViewCellID = @"NearbyTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _searchbgView.layer.borderWidth = 1;
    _searchbgView.layer.borderColor = RGBCOLOR(226, 235, 241).CGColor;
    _searchAddress.delegate = self;
    [_nearbyTableView registerNib:[UINib nibWithNibName:@"NearbyTableViewCell" bundle:nil] forCellReuseIdentifier:NearbyTableViewCellID];
}



#pragma mark === TableViewDelegate ===
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60.5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NearbyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NearbyTableViewCellID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


#pragma mark === UITextFieldDelegate ===
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    _searchLabel.hidden = YES;
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if ([textField.text isEqualToString:@""]) {
        _searchLabel.hidden = NO;
    }
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_searchAddress resignFirstResponder];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [_searchAddress resignFirstResponder];
    SearchAddressViewController *search = [[SearchAddressViewController alloc] init];
    search.searchString = textField.text;
    [self.navigationController pushViewController:search animated:YES];
    return YES;
}

- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
